﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace FIS.iDET.TemplateCreator
{

    public partial class FormTemplateCreator : Form
    {
        public static double zoomFactor = 1;
        ImageService tifImage = null;
        public int count = 0;

        private Point startPoint = new Point(0, 0);
        private Point imageStartPoint = new Point(0, 0);
        private Point endPoint = new Point(0, 0);
        DoubleRectangle rect = new DoubleRectangle(0, 0, 0, 0);
        public static int rows = 1;

        public FormTemplateCreator()
        {
            InitializeComponent();
        }

        private void createButton_Click(object sender, EventArgs e)
        {
            FormEdit formEdit = new FormEdit(this, false);
            formEdit.ShowDialog();
        }

        private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > -1)
            {
                dataGridView.CurrentCell = dataGridView[e.ColumnIndex, 0];
                dataGridView.CurrentCell.Selected = true;
                editButton_Click(null, null);
            }
        }

        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedCells != null)
            {
                int i = dataGridView.SelectedCells[0].ColumnIndex;
                if (MessageBox.Show("Are you sure you want to delete this field: " + dataGridView.Columns[i].HeaderText,
                    "Deleting field",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    GlobalVariables.columns.RemoveAt(i);
                    dataGridView.Columns.RemoveAt(i);
                    if (dataGridView.Columns.Count == 0)
                        saveButton.Enabled = false;
                }
            }
            else
            {
                MessageBox.Show("You have not set any column to delete");
            }
        }

        private void editButton_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedCells != null)
            {
                FormEdit formEdit = new FormEdit(this, true);
                formEdit.ShowDialog();
            }
            else
            {
                MessageBox.Show("You have not set any column to delete");
            }
        }

        private void FormTemplateCreator_Load(object sender, EventArgs e)
        {
            // init registry service

            RegistryService.Init();

            // if app is not activated
            if (!LicenseService.AppIsActivated())
            {
                // show license windows
                LicenseKeyForm licenseKeyForm = new LicenseKeyForm();
                licenseKeyForm.ShowDialog();
            }
            else
            {
                comboBoxZoomRatio.SelectedIndex = 4;
                textBoxRowsNumber.Text = "1";
                this.Text += " - " + GlobalVariables.Version;
            }
        }

        private void loadButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "FIS.iDET Template|*.fis";
            openFileDialog.Title = "Load template";
            openFileDialog.ShowDialog();
            if (openFileDialog.FileName != null && openFileDialog.FileName != "")
            {
                // clear data grid view
                newButton_Click(null, null);
                
                // get column info from XML
                GlobalVariables.columns = XmlService.ReadXml(openFileDialog.FileName);

                //set zoom
                comboBoxZoomRatio.Text = ((int)(zoomFactor * 100)).ToString();

                if (GlobalVariables.columns == null)
                {
                    // cannot load data
                    MessageBox.Show("Cannot load template, please make sure that it is valid!");
                }
                else
                {
                    // set column info to datagridview
                    foreach (DataColumn column in GlobalVariables.columns)
                    {
                        // add new column
                        int i = dataGridView.Columns.Add((count++).ToString(), column.Header.Trim());
                        dataGridView.Columns[i].ToolTipText = "Drag to re-order this field";
                        dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                        dataGridView.Columns[i].Width = column.Width;

                        // add one new row if there is none
                        if (dataGridView.RowCount == 0)
                            dataGridView.Rows.Add();

                        // set data type to row
                        dataGridView.Rows[0].Cells[i].Value = XmlService.getDataTypeLongNameOf(column.Type);
                        dataGridView.Rows[0].Cells[i].ToolTipText = "Double click to edit this Data type";
                    }
                    dataGridView.Rows[0].Cells[0].Selected = true;
                    if (GlobalVariables.TemplatePageCol != 0)
                    {
                        checkBoxPageNumber.Checked = true;
                        checkBoxPageNumber_CheckedChanged(null, null);
                    }
                }
            }
        }

        private void newButton_Click(object sender, EventArgs e)
        {
            dataGridView.CurrentCell = null;
            while (dataGridView.ColumnCount > 0)
                dataGridView.Columns.RemoveAt(0);
            GlobalVariables.columns.Clear();
            pictBox.Image = null;
            EnableMenuIcons(false);
            saveButton.Enabled = false;
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "FIS.iDET Template|*.fis";
            saveFileDialog.Title = "Save template";
            saveFileDialog.ShowDialog();
            if (saveFileDialog.FileName != null && saveFileDialog.FileName != "")
            {
                XmlService.WriteXml(saveFileDialog.FileName, dataGridView);
            }
        }

        private void LoadImage()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Tif Images|*.tif|Tiff Images|*.tiff|All files|*.*";
            openFileDialog.Title = "Open Tiff Image";
            DialogResult result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK && !String.IsNullOrEmpty(openFileDialog.FileName))
            {
                // load tif file
                tifImage = new ImageService(openFileDialog.FileName);

                if (tifImage.FileLoadedOK)
                {
                    // if template is in multipage mode, asks user to load excel file for this mode to work
                    {
                        textBoxPageNumber.ReadOnly = false;
                        textBoxPageNumber.Text = (tifImage.CurrentFrame + 1).ToString();
                    }

                    // set max page to toolStripLabelPage
                    labelPage.Text = "/" + tifImage.TotalFrames.ToString();

                    // enable menu items
                    

                    // disable previous page button
                    buttonPreviousPage.Enabled = false;


                    // set default zoom factor
                    tifImage.SetImageFrame(0);
                    if (dataGridView.CurrentCell != null)
                    {
                        int id = dataGridView.CurrentCell.ColumnIndex;
                        rect.X = GlobalVariables.columns[id].X;
                        rect.Y = GlobalVariables.columns[id].Y;
                        rect.Width = GlobalVariables.columns[id].W;
                        rect.Height = GlobalVariables.columns[id].H;
                    }
                    pictBox.Image = tifImage.GetImageZoom(zoomFactor,rect);

                    EnableMenuIcons(true);
                    if (tifImage.TotalFrames == 1)
                        buttonNextPage.Enabled = false;
                }
                else
                {
                    ResetImageBox();
                }
            }
        }

        private void EnableMenuIcons(Boolean enabled)
        {
            buttonNextPage.Enabled = enabled;
            buttonPreviousPage.Enabled = enabled;
            textBoxPageNumber.Enabled = enabled;
            comboBoxZoomRatio.Enabled = enabled;

            // H.NH added
            pictBox.Enabled = enabled;
            buttonRowHeight.Enabled = enabled;
            numericUpDown1.Enabled = enabled;
            textBoxRowsNumber.Enabled = enabled;
        }

        private void EnableButtonSize(Boolean enabled)
        {
            buttonPositionDown.Enabled = enabled;
            buttonPositionLeft.Enabled = enabled;
            buttonPositionRight.Enabled = enabled;
            buttonPositionUp.Enabled = enabled;
            buttonSizeDown.Enabled = enabled;
            buttonSizeUp.Enabled = enabled;
            buttonSizeLeft.Enabled = enabled;
            buttonSizeRight.Enabled = enabled;
            numericSpin.Enabled = enabled;
            // reverse
            textBoxRowsNumber.Enabled = !enabled;
            buttonRowHeight.Enabled = !enabled;
        }

        private void ResetImageBox()
        {

            // delete image
            pictBox.Image = null;

            // disable menu items
            EnableMenuIcons(false);
            pictBox.Enabled = false;
            EnableButtonSize(false);
        }

        private void buttonLoadImage_Click(object sender, EventArgs e)
        {
            LoadImage();
        }
        private void RedrawPicture() // mode = 1 draw multiple rect
        {
            RedrawPicture(false);
        }

        private void RedrawPicture(bool mode) // mode = 1 draw multiple rect

        {
            /*if (navigationToolStripMenuItem.Checked)
            {
                DoubleRectangle rect;
                if (GlobalConstants.TemplatePageCol == 0)
                {
                    rect = GetCurrentCellRectSingleLine();
                }
                else
                {
                    rect = GetCurrentCellRectMultiLine();
                }
                PictBox.Image = tifImage.GetImageZoom(zoomFactor, rect);
            }
            else             */
            if (pictBox.Enabled)
            {
                pictBox.Image = tifImage.GetImageZoom(zoomFactor, rect, mode);
                pictBox.Refresh();
            }
        }

        private void textBoxPageNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ( e.KeyChar == (char)Keys.Enter)
            {
                try
                {
                    int page = Convert.ToInt32(textBoxPageNumber.Text);
                    int frameToDisplay = 0;
                    if (page > 0 && page <= tifImage.TotalFrames)
                    {
                        frameToDisplay = page - 1;
                        // set image
                        tifImage.SetImageFrame(frameToDisplay);
                        RedrawPicture();
                        if (page == 1)
                        {
                            buttonNextPage.Enabled = true;   
                            buttonPreviousPage.Enabled = false;
                        }
                        if (page == tifImage.TotalFrames)
                        {
                            buttonNextPage.Enabled = false;   
                            buttonPreviousPage.Enabled = true;
                        }
                    }
                    else
                        textBoxPageNumber.Undo();
                }
                catch
                {
                    textBoxPageNumber.Undo();
                }
            }
        }

        private void buttonPreviousPage_Click(object sender, EventArgs e)
        {
            tifImage.SetImageFrame(tifImage.CurrentFrame-1);
            RedrawPicture();
            textBoxPageNumber.Text = (tifImage.CurrentFrame+1).ToString();
            if (tifImage.CurrentFrame == 0)
                buttonPreviousPage.Enabled = false;
            if (tifImage.CurrentFrame < tifImage.TotalFrames-1)
                buttonNextPage.Enabled = true;
        }

        private void buttonNextPage_Click(object sender, EventArgs e)
        {
            tifImage.SetImageFrame(tifImage.CurrentFrame+1);
            RedrawPicture();
            textBoxPageNumber.Text = (tifImage.CurrentFrame+1).ToString();
            if (tifImage.CurrentFrame == tifImage.TotalFrames-1)
                buttonNextPage.Enabled = false;
            if (tifImage.CurrentFrame > 0)
                buttonPreviousPage.Enabled = true;
        }


        /* private Point ConvertToImageCoordinate(Point pictPoint)
        {
            Point imagePoint= new Point(0,0);

             int offsetX = panelPictBox.HorizontalScroll.Value / panelPictBox.HorizontalScroll.Maximum * (tifImage.Width - panelPictBox.Width);
            int x = (int)((rect.X + rect.Width - offsetX) * zoomFactor) + 10;
            
            int offsetY = panelPictBox.VerticalScroll.Value / panelPictBox.VerticalScroll.Maximum * (tifImage.Height - panelPictBox.Height);
            int y = (int)((rect.Y + rect.Height / 2 - offsetY) * zoomFactor) - 10; 
            return imagePoint;
        } */
        bool dragging = false;
        private void pictBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && dataGridView.Columns.Count > 0 && pictBox.Enabled)
            {
                EnableButtonSize(false);
                dragging = true;
                pictBox.Cursor = Cursors.Cross;
                startPoint.X = e.Location.X;
                startPoint.Y = e.Location.Y;
                //imageStartPoint = ConvertToImageCoordinate(startPoint);
            }
        }

        private void pictBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && dataGridView.Columns.Count> 0 && pictBox.Enabled && dragging )
            {
                

                int x = startPoint.X < e.Location.X ? startPoint.X : e.Location.X;
                int y = startPoint.Y < e.Location.Y ? startPoint.Y : e.Location.Y;

                rect.X = (int) (x / zoomFactor);
                rect.Y = (int) (y / zoomFactor);
                rect.Width = Math.Abs((int)((e.Location.X - startPoint.X)/zoomFactor));
                rect.Height = Math.Abs((int)((e.Location.Y - startPoint.Y)/zoomFactor));
                //GlobalVariables.columns[curCol].Rect = rect;
                RedrawPicture();
            }
        }

        

        private void pictBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (dataGridView.Columns.Count > 0 && pictBox.Enabled && dragging)
            {
                dragging = false;
                int curCol = dataGridView.CurrentCell.ColumnIndex;

                int x = startPoint.X < e.Location.X ? startPoint.X : e.Location.X;
                int y = startPoint.Y < e.Location.Y ? startPoint.Y : e.Location.Y;

                rect.X = (int)(x / zoomFactor);
                rect.Y = (int)(y / zoomFactor);
                rect.Width = Math.Abs((int)((e.Location.X - startPoint.X) / zoomFactor));
                rect.Height = Math.Abs((int)((e.Location.Y - startPoint.Y) / zoomFactor));
                
                //  Improve Rect Accuracy
                
                // rectMultiRow = rect;
                
                RedrawPicture();
            }
        }

        private void comboBoxZoomRatio_SelectedIndexChanged(object sender, EventArgs e)
        {
            //PictBox.Focus();
            if (comboBoxZoomRatio.SelectedIndex < 0) comboBoxZoomRatio.SelectedIndex = 4; //handle exception

            // else init zoom
            int pos = comboBoxZoomRatio.Text.IndexOf('%');
            string zoomFactorString = comboBoxZoomRatio.Text.Remove(pos);
            zoomFactor = Convert.ToDouble(zoomFactorString) / 100;

            // active zoom buttons
            RedrawPicture(true);
        }

        private void comboBoxZoomRatio_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                int pos = comboBoxZoomRatio.Text.IndexOf('%');
                string zoomFactorString = comboBoxZoomRatio.Text;
                if (pos > -1)
                    zoomFactorString = comboBoxZoomRatio.Text.Remove(pos);
                else
                    comboBoxZoomRatio.Text += "%";
                double dzoomFactor = 0;

                // end zoomComboBox
                if (double.TryParse(zoomFactorString, out dzoomFactor) && dzoomFactor > 0 && dzoomFactor < 500)
                {
                    zoomFactor = Convert.ToDouble(zoomFactorString) / 100;
                    RedrawPicture();
                }
                else comboBoxZoomRatio.SelectedIndex = 4;
            }
        }

        private void dataGridView_CurrentCellChanged(object sender, EventArgs e)
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled)
            {
                rect = GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].Rect;
                RedrawPicture();
                if (rect.Height != 0 && rect.Width != 0)
                    EnableButtonSize(true);
                else EnableButtonSize(false);
            }
            if (dataGridView.Columns.Count > 0)
                saveButton.Enabled = true;
            else
                saveButton.Enabled = false;
            if (dataGridView.CurrentCell != null)
            {
                editButton.Enabled = true;
                deleteButton.Enabled = true;
            }
            else
            {
                editButton.Enabled = false;
                deleteButton.Enabled = false;
            }
        }

        private void checkBoxPageNumber_CheckedChanged(object sender, EventArgs e)
        {
            comboBoxPageCol.Enabled = checkBoxPageNumber.Checked;
            comboBoxPageCol.Items.Clear();
            if (checkBoxPageNumber.Checked)
            {
                for (int i = 1; i <= dataGridView.Columns.Count; i++)
                    comboBoxPageCol.Items.Add(i);
                if (GlobalVariables.TemplatePageCol == 0 ||
                    GlobalVariables.TemplatePageCol > dataGridView.Columns.Count)
                {
                    GlobalVariables.TemplatePageCol = dataGridView.Columns.Count;
                }
                comboBoxPageCol.SelectedIndex = GlobalVariables.TemplatePageCol - 1;
            }
            else
            {
                GlobalVariables.TemplatePageCol = 0;  
            }
        }

        private void dataGridView_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView.Columns.Count > 0)
                saveButton.Enabled = true;
            else
                saveButton.Enabled = false;
            if (dataGridView.CurrentCell != null)
            {
                editButton.Enabled = true;
                deleteButton.Enabled = true;
            }
            else
            {
                editButton.Enabled = false;
                deleteButton.Enabled = false;
            }
            //MessageBox.Show("yep");
        }

        private void moveTooltipLeftToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled)
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].X-=(int) numericSpin.Value;
                rect.X -= (int)numericSpin.Value;
                RedrawPicture(true);
            }
        }

        private void moveTooltipRightToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].X += (int)numericSpin.Value;
                rect.X += (int)numericSpin.Value;
                RedrawPicture(true);
            }
        }

        private void moveTooltipUpToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].Y -= (int)numericSpin.Value;
                rect.Y -= (int)numericSpin.Value;
                RedrawPicture(true);
            }
        }

        private void moveTooltipDownToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].Y++;
                rect.Y += (int)numericSpin.Value;
                RedrawPicture(true);
            }
        }

        private void increaseTooltipHeightToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].H++;
                rect.Height ++;
                RedrawPicture(true);
            }
        }

        private void increaseTooltipWidthToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].W++;
                rect.Width++;
                RedrawPicture(true);
            }
        }

        private void decreaseTooltipHeightToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].H--;
                rect.Height --;
                RedrawPicture(true);
            }
        }

        private void decreaseTooltipWidthToolStripMenuItem_Click()
        {
            if (dataGridView.CurrentCell != null && pictBox.Enabled )
            {
                GlobalVariables.columns[dataGridView.CurrentCell.ColumnIndex].W--;
                rect.Width--;
                RedrawPicture(true);
            }
        }

        // Shorcut key comming here
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Control | Keys.Shift | Keys.Up:
                    moveTooltipUpToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Shift | Keys.Down:
                    moveTooltipDownToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Shift | Keys.Left:
                    moveTooltipLeftToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Shift | Keys.Right:
                    moveTooltipRightToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Alt | Keys.Right:
                    increaseTooltipWidthToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Alt | Keys.Up:
                    decreaseTooltipHeightToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Alt | Keys.Left:
                    decreaseTooltipWidthToolStripMenuItem_Click();
                    return true;
                case Keys.Control | Keys.Alt | Keys.Down:
                    increaseTooltipHeightToolStripMenuItem_Click();
                    return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void buttonPositionUp_Click(object sender, EventArgs e)
        {
            moveTooltipUpToolStripMenuItem_Click();
        }

        private void buttonPositionDown_Click(object sender, EventArgs e)
        {
            moveTooltipDownToolStripMenuItem_Click();
        }

        private void buttonPositionLeft_Click(object sender, EventArgs e)
        {
            moveTooltipLeftToolStripMenuItem_Click();
        }

        private void buttonPositionRight_Click(object sender, EventArgs e)
        {
            moveTooltipRightToolStripMenuItem_Click();
        }

        private void buttonSizeUp_Click(object sender, EventArgs e)
        {
            decreaseTooltipHeightToolStripMenuItem_Click();
        }

        private void buttonSizeDown_Click(object sender, EventArgs e)
        {
            increaseTooltipHeightToolStripMenuItem_Click();
        }

        private void buttonSizeLeft_Click(object sender, EventArgs e)
        {
            decreaseTooltipWidthToolStripMenuItem_Click();
        }

        private void buttonSizeRight_Click(object sender, EventArgs e)
        {
            increaseTooltipWidthToolStripMenuItem_Click();
        }

        private void comboBoxPageCol_SelectedIndexChanged(object sender, EventArgs e)
        {
            GlobalVariables.TemplatePageCol = comboBoxPageCol.SelectedIndex + 1;
        }

        private void dataGridView_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            if (checkBoxPageNumber.Checked == true)
                checkBoxPageNumber_CheckedChanged(null, null);
        }

        private void dataGridView_ColumnRemoved(object sender, DataGridViewColumnEventArgs e)
        {
            if (checkBoxPageNumber.Checked == false) return;

            if (dataGridView.Columns.Count == 0)
            {
                comboBoxPageCol.Enabled = checkBoxPageNumber.Checked = false;
            }
            else
            {
                checkBoxPageNumber_CheckedChanged(null, null);
            }
        }

        public int valueUpDown = 0;
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            /*if (numericUpDown1.Value > valueUpDown)
            {*/
                // valueUpDown = (int)numericUpDown1.Value;
                /// rect.Y = (int)((double)rectMultiRow.Y + (double)rectMultiRow.Height * ((double)valueUpDown / (double)rows));
            if (numericUpDown1.Value > valueUpDown)
            {
                valueUpDown = (int)numericUpDown1.Value;
                rect.Y += rect.Height;
            }
            else
            {
                valueUpDown = (int)numericUpDown1.Value;
                rect.Y -= rect.Height;
            }
                RedrawPicture();
            /*}
            else
            {
                valueUpDown = (int)numericUpDown1.Value;
                rect.Y = (int)((double)rectMultiRow.Y - (double)rectMultiRow.Height * ((double)valueUpDown / (double)rows));
                RedrawPicture();
            }*/
        }

        private void buttonRowHeight_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentCell!=null && pictBox.Enabled && rect.Height!=0 && rect.Width!=0 )
                if (Int32.TryParse(textBoxRowsNumber.Text, out rows))
                {
                    EnableButtonSize(true);
                    int curCol = dataGridView.CurrentCell.ColumnIndex;
                    if (rows < 1)
                    {
                        rows = 1;
                        textBoxRowsNumber.Text = rows.ToString();
                    }
                    //rect1row.Width = (rect.Width / rows);
                    rect.Height = (rect.Height / rows);
                    GlobalVariables.columns[curCol].Rect = rect;
                    RedrawPicture(true); // true means draw multiple Rect mode
                    //buttonRowHeight.Enabled = false;
                    return;
                }
                else
                {
                    MessageBox.Show("Please enter number of Rows in Navigation zone correctly !", "Wrong rows number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    textBoxRowsNumber.Focus();
                }
            buttonRowHeight.Enabled = false;
        }

        private void textBoxRowsNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            buttonRowHeight.Enabled = true;
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void numericSpin_ValueChanged(object sender, EventArgs e)
        {

        }

        private void buttonAbout_Click(object sender, EventArgs e)
        {
            FormAbout formAbout = new FormAbout();
            formAbout.Show();
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}